package com.framework.web.bus.service;
import com.framework.web.bus.domain.Ingredients;
import com.framework.web.bus.repository.IngredientsRepository;
import com.framework.web.bus.repository.specifications.IngredientsSpecs;
import com.framework.web.common.domain.BusinessConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

/**
* @Title: Service
* @Description: 业务层
* @author fusf
* @date 2016-09-08
* @version V1.0
*
*/
@Service
public class IngredientsService {

@Autowired
private IngredientsRepository  ingredientsRepository;

/**
* 新增或者保存
* @param ingredients
* @return
*/
public Ingredients save(Ingredients ingredients) {
    return ingredientsRepository.save(ingredients);
}

/**
* 删除
* @param id
*/
public void  delete(String id) {
    Ingredients ingredients = ingredientsRepository.findOne(id);
    ingredients.setStatus(BusinessConstants.status.STATUS_remove);
    ingredientsRepository.save(ingredients);
}
/**
* 根据id查询
* @param id
* @return
*/
public Ingredients findById(String id) {
    return ingredientsRepository.findOne(id);
}


/**
* 分页查找
* @param ingredients
* @param pr
* @return
*/
public Page<Ingredients> getPageList(Ingredients ingredients, PageRequest pr) {
    Page<Ingredients> totalList = ingredientsRepository.findAll(IngredientsSpecs.pageQueryIngredients(ingredients), pr);
    return totalList;
}

}
